package dome_011;

import java.util.concurrent.TimeUnit;

/**
 * <p>Description: [ThreadLocal线程局部变量]</p>
 * Created on 2020/12/14
 *
 * @author <a href="mailto: 819712047@qq.com">谢振东 </a>
 * @version 1.0
 */
public class ThreadLocal1 {

    volatile static Person p = new Person();

    public static void main(String[] args) {
        System.out.println(Thread.currentThread().getName() + "已启动");

        new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "已启动");
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (Exception e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "睡眠结算");
            System.out.println(p.name);
        }).start();

        new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "已启动");
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (Exception e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "睡眠结算");
            p.name = "lisi";
        }).start();
    }
}

class Person{
    String name = "zhangsan";
}
